#include <main.h>
#include <stdio.h>
#include <stdlib.h>
#include <parser.h>
#include <string.h>
#include <symtab.h>

int verifyExtension(char const *filename, char *extension){
  int i = strlen(extension);
  
  while(i > 0){
    if(filename[strlen(filename) - i] != extension[strlen(extension) - i]) return 0;
    i--;
  }
  
  return 1;
}

main(int argc, char const *argv[])
{
    
    if (argc > 1){
	if (verifyExtension(argv[1],".mypas"))tape = fopen(argv[1], "r");
	else{
	  fprintf(stderr, "File not supported (try files with \"mypas\" extension)\n");
	  exit(-1);
	}
    }else
	tape = stdin;

    lookahead = gettoken();
    
    program();

    printf("\n");
    
    print_symtab();

    exit(0);
}